package blog.controller;

import javax.servlet.http.HttpSession;

import blog.forms.User;

public class UserController {

	private static String currentUser = "cUser";
	
	public static void logIn(User user, HttpSession session) {
		
		session.setAttribute(currentUser, user);
	}
	
	public static void logOut(HttpSession session) {
		
		if(session != null)
			session.invalidate();
	}
	
	public static User getUser(HttpSession session) {
		if(session != null)
			return (User)session.getAttribute(currentUser);
		return null;
	}

	public static boolean isLogged(HttpSession session) {
		User user = (User)session.getAttribute(currentUser);
		if(user == null)
			return false;
		return true;
	}
	public static boolean isAdmin(HttpSession session) {
		User user = (User)session.getAttribute(currentUser);
		if(user == null)
			return false;
		else if("admin".equals(user.getLogin()))
			return true;
		return false;
	}
	public static boolean isAdmin(HttpSession session, User user) {
		if(user == null)
			return false;
		else if("admin".equals(user.getLogin()))
			return true;
		return false;
	}
}
